<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');

    const text = 'HELLO';
    ctx.font = 'bold 150px Arial';

    // 获取文字宽度，要在font之后获取
    const { width } = ctx.measureText(text);
    console.log(width);

    ctx.fillStyle = 'yellow';
    ctx.strokeStyle = 'maroon';

    ctx.lineWidth = 4;

    /* 填充文字 fillText(text,x,y,maxWidth) */
    ctx.fillText(text,50,200);
    
    /* 描边文字 strokeText(text,x,y,maxWidth) */
    ctx.strokeText(text,50,200);

    /* 文字最大宽 */
    ctx.fillText(text,50,400, width / 2);
    ctx.fillText(text,50,600, width * 2);


  </script>
</body>
</html>